<?php
session_start();
    
    // Created By : Julian Ponce
    // B.S. Computer Science - De La Salle Canlubang
    // January 9, 2012
    // IN PARAMETERS : documentId
    // 
    // This AJAX Requests gets all remarks of a particular docmentId.

    include('../includes/siteConfig.php');
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    $documentId = $_POST['documentId'];
    
    // GET REMARKS OF A DOCUMENT
    $query = 
        "
            SELECT *
            FROM Remark, Account
            WHERE Remark.documentId = '$documentId' AND 
                  Remark.userId = Account.userId
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
     
    
    if (mysql_num_rows($result) > 0) {
        // SAVE QUERY RESULTS TO AN ARRAY > $row. Each row will be placed to a list ($remarkList).  
        while ($row = mysql_fetch_array($result)) {
            $remarkData = array();
            $remarkData['userFullName'] = $row['firstName'] . $row['lastName'];
            $remarkData['remark'] = $row['remark'];
            $remarkData['remarkDateTime'] = $row['remarkDateTime'];
            $remarkList[] = $remarkData;
        }
        
        echo json_encode($remarkList);
    }
    
    else {
        echo json_encode(0);
    }
    
    mysql_free_result($result);
    mysql_close($connect);
?>
